<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>键盘事件</title>
  <script type="text/javascript">
	//键盘事件： keydown、keyup、keypress
	// keydown 键盘按下触发的事件， keyup键盘松开触发的事件， keypress按下不松开连续触发的事件
	//event监听鼠标，键盘等信息的一个对象
	function testKey1(event){
		var key = event.keyCode;
		document.getElementById('show').value = key +" --> "+ String.fromCharCode(key);
	}

	function testkey2(event){
		var key = event.keyCode;
		document.getElementById('show').value = key +" --> "+ String.fromCharCode(key);
	}

	function testkey3(event){
		var key = event.keyCode;
		document.getElementById('show').value += key +" --> "+ String.fromCharCode(key)+"\n";
	}

  </script>
 </head>
 <body>
	键盘按下触发事件：<input type="text" id="number1" onkeydown="testKey1(event);" /><br/>
	键盘松开触发事件：<input type="text" id="number2" onkeyup='testkey2(event);'/><br/>
	键盘按下不松开：<input type="text" id="number3" onkeypress="testkey3(event)"/><br/>
	<textarea id="show" style="width:500px;height:300px;"></textarea>
 </body>
</html>
